<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/12/6 0006
  Time: 14:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page import="cn.school.service.*,cn.school.entity.*,java.util.List" %>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery-3.4.1.min.js"></script>
    <script>
        $(function(){
            $("#go").keydown(function(event){
                if(event.keyCode==13){//回车
                    window.location="student.jsp?pageNo="+$(this).val()+"&sname="+$("[name=sname]").val()+"&tel="+$("[name=tel]").val();
                }
            });
        });
    </script>
</head>
<body>
<%@include file="checkLogin.jsp"%>
<%
    StudentService service=new StudentService();
    int pageNo=1;
    try{
        pageNo=Integer.parseInt(request.getParameter("pageNo"));
    }catch(Exception e){}
    String name=request.getParameter("sname");
    name=name==null?"":name;
    String tel=request.getParameter("tel");
    tel=tel==null?"":tel;

    List<Student> list=service.search(pageNo, 20, name, tel, null, null);
    int total=service.searchTotal(name, tel, null, null);
    int pageTotal=total/20+(total%20==0?0:1);//总页数

%>
<form action="student.jsp" method="get" style="width: 50%;margin: 0 auto">
    <input type="text" name="sname" placeholder="姓名" value="<%=name==null?"":name%>"/>
    <input type="text" name="tel" placeholder="电话" value="<%=tel==null?"":tel%>"/>
    <input type="date" name="enterStart" placeholder="开始时间"/>
    <input type="date" name="enterEnd" placeholder="结束时间"/>
    <input type="submit" value="搜索"/>
</form>
<a href="addStudent.jsp">增加</a>
<table border="2px" cellpadding="0" cellspacing="0" align="center" width="90%">
<%

    for(Student s:list){
%>
<tr>
    <td><%=s.getStuno()%></td><td><%=s.getSname() %></td><td><%=s.getTelephone() %></td>
    <td>
        <a href="showStudentServlet?stuno=<%=s.getStuno()%>">差看详情</a>
        <a onclick="return window.confirm('真的要删除？')" href="delStudent.jsp?stuno=<%=s.getStuno()%>">删除</a>
        &nbsp;
        <a  href="updateStudent.jsp?stuno=<%=s.getStuno()%>">修改</a>
    </td>
</tr>
<%} %>
</table>
<p align="center">
    <%
        if(pageNo>1){
    %>
    <a href="student.jsp?pageNo=<%=pageNo-1%>&sname=<%=name%>&tel=<%=tel%>">上一页</a>
    <%} %>
    <input type="number" min="1" value="<%=pageNo%>" id="go"/>
    <%
        if(pageTotal>pageNo){
    %>
    <a href="student.jsp?pageNo=<%=pageNo+1%>&sname=<%=name%>&tel=<%=tel%>">下一页</a>
    <%} %>
    <a href="student.jsp?pageNo=<%=pageTotal%>&sname=<%=name%>&tel=<%=tel%>">末页</a>
</p>
</body>
</html>
